<template>
	<view class="part-three">
		<view class="part-time">
			<swiper class="time-box" previous-margin="30rpx" next-margin="420rpx">
				<swiper-item class="flex-center" v-for="(item,index) in charteredBusList" :key="index">
					<view class="time-item" :class="itemIndex==index?'time-on':''" @click="changeTimeType(item,index)">
						<view class="time-name">
							{{item.dayPackageInfo.dailyDuration}}小时包车
						</view>
						<view class="time-peice">
							含{{item.dayPackageInfo.dailyDistance}}公里/{{item.price}}元起
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="part-type">
			<view class="type-item" :class="carIndex==index?'type-on':''" v-for="(item,index) in charteredBusList" :key="index"
				@click="changeCarType(item, index)">
				<image class="type-img" src="../../static/logo.png" mode=""></image>
				<view class="type-box">
					<view class="type-title">
						{{item.vehicleTypeName}}
					</view>
					<view class="type-price">
						<text class="type-price-icon">￥</text>
						<text class="type-price-num">{{item.price}}</text>
						<text class="type-price-icon-none">￥</text>
						<text class="type-price-price-none">{{item.charteredPrice}}</text>
					</view>
				</view>
			</view>
		</view>
		<!--最底下按钮-->
		<view class="flex bottom-fix">
			<view class="cu-bar bg-white half-width">
				<view class="item-width-1">
					<text class="font-28-333333" style="margin-right: 20upx;">总金额</text>
					<text class="text-sm text-orange2">¥</text>
					<text class="text-lg font-bold text-orange2">{{priceText}}</text>
				</view>
			</view>
			<view class="cu-bar bg-gradual-orange submit-btn justify-center" @click="handleSubmit">立即预约</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		computed: {
			...mapState(['charteredBusList'])
		},
		data() {
			return {
				itemIndex: 0, //选中的包时下标
				carIndex: 0, //选中的车型下标
				typeList: [], //车型列表
				timeForm: {}, //选中的包时
				typeForm: {}, //选中的车型
				days:'',//包车天数
				priceText: 0
			};
		},
		onLoad(query) {
			if(query.days){
				this.days = query.days
			}
			this.priceText = this.charteredBusList[0].price;
			this.typeForm = this.charteredBusList[0];
			this.timeForm = this.charteredBusList[0];
		},
		methods: {
			changeTimeType(item, index) {
				this.itemIndex = index;
				this.carIndex = 0;
				this.priceText = item.price;
				this.typeForm = item;
			},
			changeCarType(item, index) {
				this.typeForm = item;
				this.carIndex = index;
				this.priceText = item.price;
			},
			handleSubmit(){
				this.$store.commit("setPrice", this.priceText);
				this.$store.commit("setServiceType", 2);
				this.$store.commit("setCharterCarForm", this.typeForm);
				/* 追加包车天数给后端 */
				this.typeForm.days = this.days
				 this.$store.commit("setSpecialCarForm", this.typeForm);
				this.$store.commit("setCarlevel", this.typeForm.vehicleType);
				this.$store.commit("setCityCode", this.typeForm.cityCode);
				uni.navigateTo({
					url: '../pay/index'
				})
			}
		}
	};
</script>

<style lang="scss">
	.part-three {
		height: 100vh;
		width: 100%;
		background: linear-gradient(180deg, #E2EFFC 0%, #FFFFFF 64%);
		padding-top: 38upx;

		.part-time {
			padding: 4upx 0 42upx 0;
		}

		.time-box {
			width: 750upx;
			height: 148upx;

			.time-item {
				width: 288upx;
				height: 148upx;
				margin-right: 10upx;
				border-radius: 10upx;
				background-color: #FFFFFF;
				border: 4rpx solid #FFFFFF;
				border-radius: 10upx;
				overflow: hidden;
				display: flex;
				flex-direction: column;
				justify-content: center;
				padding: 0 22upx;
				box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.08);

				.time-name {
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: 30upx;
					font-weight: bold;
				}

				.time-peice {
					font-size: 24upx;
					color: #666666;
					margin-top: 20upx;
				}
			}

			.time-on {
				border: 4rpx solid #3888FC;
			}
		}

		.part-type {
			padding: 0 30upx;
			padding-bottom: 188upx;
			.type-item {
				background: #FFFFFF;
				box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.08);
				border-radius: 10upx;
				padding: 30upx;
				display: flex;
				margin-bottom: 10upx;
				border: 4rpx solid #FFFFFF;

				.type-img {
					width: 148upx;
					height: 148upx;
				}

				.type-box {
					margin-left: 22upx;

					.type-title {
						font-size: 34upx;
						font-weight: bold;
						color: #333333;
					}

					.type-price {
						margin-top: 28upx;

						.type-price-icon {
							font-size: 24upx;
							color: #FF4E18;
							margin-right: 5upx;
						}

						.type-price-num {
							font-size: 38upx;
							color: #FF4E18;
							font-weight: bold;
						}

						.type-price-icon-none {
							font-size: 14upx;
							color: #999999;
							margin-left: 20upx;
						}

						.type-price-price-none {
							font-size: 22upx;
							color: #999999;
							text-decoration: line-through;
						}
					}
				}
			}

			.type-on {
				border: 4rpx solid #3888FC;
			}
		}
	}

	/* 最底部的按钮 */
	.flex {
		display: flex;
	}

	.bottom-fix {
		position: fixed;
		bottom: 0px;
		width: 100%;
		box-shadow: 0px 0px 20upx 0px rgba(0, 0, 0, 0.08);
		padding-bottom: constant(safe-area-inset-bottom);
		/* 兼容 iOS < 11.2 */
		padding-bottom: env(safe-area-inset-bottom);
		/* 兼容 iOS >= 11.2 */
		background-color: #FFFFFF;
	}

	.cu-bar {
		display: flex;
		position: relative;
		align-items: center;
		min-height: 98upx;
		justify-content: space-between;
	}

	.bg-white {
		background-color: #FFFFFF;
		color: #808080;
	}

	.half-width {
		padding: 0 30upx;
		flex: 1;
	}

	.item-width-1 {
		width: 70%;
	}

	.font-28-333333 {
		color: #333333;
		font-size: 28upx;
	}

	.text-sm {
		font-size: 22upx;
		margin-right: 10upx;
	}

	.text-orange2 {
		color: #FF4E18;
	}

	.text-lg {
		font-size: 36upx;
	}

	.font-bold {
		font-weight: bold;
	}

	.item-width-2 {
		width: 30%;
		padding-left: 30upx;
		border-left: 1upx solid rgba(0, 0, 0, 0.1);
	}

	.align-center {
		align-items: center;
	}

	.font-28-666666 {
		color: #666666;
		font-size: 28upx;
	}

	.bg-gradual-orange {
		background: linear-gradient(0deg, #2281FF 0%, #4E9AFD 100%);
		color: #FFFFFF;
	}

	.submit-btn {
		width: 300upx;
		justify-content: center;
		font-size: 36upx;
		font-weight: bold;
	}

	.justify-center {
		justify-content: center;
	}
</style>
